package com.mjf.cjt.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mjf.cjt.domain.TfClass;
import com.mjf.cjt.mapper.TfClassMapper;
import com.mjf.cjt.service.AsyncTMService;
import com.mjf.cjt.service.TfClassService;
import com.mjf.cjt.vo.TFClassVO;
import io.jsonwebtoken.lang.Collections;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * desc
 * </p>
 *
 * @author chenshoumeng
 * @date 2025/6/19 13:17
 */
@Service
public class TfClassServiceImpl extends ServiceImpl<TfClassMapper, TfClass> implements TfClassService {

    @Autowired
    private AsyncTMService asyncTMService;


    @Override
    @Transactional(rollbackFor = Exception.class)
    public void asyncFL() {
        List<TFClassVO> tfClassVOS = asyncTMService.asyncFL();
        if(Collections.isEmpty(tfClassVOS)) {
            return;
        }
        List<TfClass> classes = new ArrayList<>();
        tfClassVOS.forEach(tfClassVO -> {
            TfClass tfClass = new TfClass();
            tfClass.setId(tfClassVO.getId());
            tfClass.setCode(tfClassVO.getCode());
            tfClass.setName(tfClassVO.getName());
            classes.add(tfClass);
        });
        saveOrUpdateBatch(classes);
    }
}
